
package com.faral.JWOL;
//import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;


public class XmlRW {

	public XmlRW(){}

  public String leggiXml(String url, String tag){
      String value="";
    SAXBuilder builder = new SAXBuilder();
     
    // command line should offer URIs or file names
    try {
    	Document document = builder.build(url);
        Element rootElement = document.getRootElement();
        List children = rootElement.getChildren(); 
        Iterator iterator = children.iterator(); 
        while (iterator.hasNext()){ 
           Element element = (Element)iterator.next(); 
          
           //Attribute attribute = (Attribute)iterator.next(); 
           String name = element.getName(); 
           
           
           
           //System.out.println(iterator);
           //System.out.println(text);
           if (name==tag){
           value = element.getValue();
           
           
           }
           
        } 
       
        
        //String text = rootElement.getText();
         }
    // indicates a well-formedness error
    catch (JDOMException e) { 
      System.out.println(url + " is not well-formed.");
      System.out.println(e.getMessage());
    }  
    catch (IOException e) { 
      System.out.println("Could not check " + url);
      System.out.println(" because " + e.getMessage());
    }
return value;
  }

  
  
}